import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import persistedState from 'vuex-persistedstate'
import user from '@/store/user'
import cart from './cart'
import { getCategory } from '@/Api/homeapi'

// const topCategory=[
//   '居家',
//   '美食',
//   '服饰',
//   '母婴',
//   '个护',
//   '严选',
//   '数码',
//   '运动',
//   '杂货'
// ]
export default new Vuex.Store({
  state: {
    list: [],
    keys: null,
    // cate:[],
    // cate: topCategory.map(item=>{return{name:item}})
  },
  getters: {
  },
  mutations: {
    getList(state, arr) {
      state.list = arr
    },
    addkey(state, key) {
      state.keys = key
    }
  },
  actions: {
    async getCate({ commit }) {
      let { data: res } = await getCategory()
      commit('getList', res.result)
    }
  },
  modules: {
    user,cart
  },
  plugins: [persistedState()]
})
